/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.controller;

import java.util.Collection;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.SaveChecks;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;

import com.xy.biz.fd.domain.resp.GetDocumentReleaseOftenUseResponse;
import com.xy.biz.fd.domain.req.GetDocumentReleaseOftenUseRequest;
import com.xy.biz.fd.domain.req.ListDocumentReleaseOftenUseRequest;
import com.xy.biz.fd.domain.req.SaveDocumentReleaseOftenUseRequest;
import com.xy.biz.fd.domain.query.DocumentReleaseOftenUseQuery;
import com.xy.biz.fd.domain.converter.DocumentReleaseOftenUseConverter;
import com.xy.biz.fd.client.DocumentReleaseOftenUseClient;
import com.xy.biz.fd.service.DocumentReleaseOftenUseService;

/**
 * 
 * 
 * @author zgy
 * @date 2021-6-15
 */
@Api(tags = "发行文档最常使用服务")
@Slf4j
@RestController
@RequestMapping("/api/fd/document_release_often_use")
public class DocumentReleaseOftenUseController implements DocumentReleaseOftenUseClient {

	@Autowired
	private DocumentReleaseOftenUseService documentReleaseOftenUseService;
	
/*	@Validatable(groups = {SaveChecks.class})
	@PostMapping(value = "/save")
	public Result<?> saveDocumentReleaseOftenUse(@RequestBody SaveDocumentReleaseOftenUseRequest request) {
		documentReleaseOftenUseService.saveDocumentReleaseOftenUse(DocumentReleaseOftenUseConverter.toBO(request));
		return Result.success();
	}
	
	@Validatable(groups = {SaveChecks.class})
	@PostMapping(value = "/save_all")
	public Result<?> saveAllDocumentReleaseOftenUse(@RequestBody Collection<SaveDocumentReleaseOftenUseRequest> collection) {
		documentReleaseOftenUseService.saveAllDocumentReleaseOftenUse(DocumentReleaseOftenUseConverter.toBO(collection));
		return Result.success();
	}
	
	@Validatable(groups = {UpdateChecks.class})
	@PostMapping(value = "/update")
	public Result<?> updateDocumentReleaseOftenUse(@RequestBody SaveDocumentReleaseOftenUseRequest request) {
		documentReleaseOftenUseService.updateDocumentReleaseOftenUse(DocumentReleaseOftenUseConverter.toBO(request));
		return Result.success();
	}*/

	@Override
	@Validatable(groups = {UpdateChecks.class})
	@ApiOperation("发行文件 “我常用的” 增加文件权重")
	@PostMapping(value = "/increment")
	public Result<?> increment(@RequestBody GetDocumentReleaseOftenUseRequest request) {
		return Result.success(documentReleaseOftenUseService.increment(request));
	}
	
/*	@Validatable
	@PostMapping(value = "/delete")
	public Result<?> deleteDocumentReleaseOftenUse(@RequestBody GetDocumentReleaseOftenUseRequest request) {
		documentReleaseOftenUseService.deleteDocumentReleaseOftenUse(request.getOftenUseId());
		return Result.success();
	}
	
	@Validatable
	@PostMapping(value = "/get")
	@Override
	public Result<GetDocumentReleaseOftenUseResponse> getDocumentReleaseOftenUse(@RequestBody GetDocumentReleaseOftenUseRequest request) {
		return Result.success(DocumentReleaseOftenUseConverter.toResponse(documentReleaseOftenUseService.getDocumentReleaseOftenUse(request.getOftenUseId())));
	}
	
	@PostMapping(value = "/list_by_ids")
	@Override
	public Result<List<GetDocumentReleaseOftenUseResponse>> listDocumentReleaseOftenUseById(@RequestBody Collection<Long> collection) {
		return Result.success(DocumentReleaseOftenUseConverter.toResponse(documentReleaseOftenUseService.listDocumentReleaseOftenUseById(collection)));
	}
	
	@PostMapping(value = "/list")
	@Override
	public Result<List<GetDocumentReleaseOftenUseResponse>> listDocumentReleaseOftenUse(@RequestBody ListDocumentReleaseOftenUseRequest request) {
		return Result.success(DocumentReleaseOftenUseConverter.toResponse(documentReleaseOftenUseService.listDocumentReleaseOftenUse(DocumentReleaseOftenUseConverter.toQuery(request))));
	}
	
	@PostMapping(value = "/count")
	@Override
	public Result<Integer> countDocumentReleaseOftenUse(@RequestBody ListDocumentReleaseOftenUseRequest request) {
		return Result.success(documentReleaseOftenUseService.countDocumentReleaseOftenUse(DocumentReleaseOftenUseConverter.toQuery(request)));
	}
	
	@PostMapping(value = "/page")
	@Override
	public Result<Page<GetDocumentReleaseOftenUseResponse>> pageDocumentReleaseOftenUse(@RequestBody ListDocumentReleaseOftenUseRequest request) {
		DocumentReleaseOftenUseQuery query = DocumentReleaseOftenUseConverter.toQuery(request);
		List<GetDocumentReleaseOftenUseResponse> list = DocumentReleaseOftenUseConverter.toResponse(documentReleaseOftenUseService.listDocumentReleaseOftenUse(query));
		int count = documentReleaseOftenUseService.countDocumentReleaseOftenUse(query);
		return Result.success(new Page<>(list, count));
	}*/
	
}
